package com.itheima.proxy.dynamic.cglib;

import net.sf.cglib.proxy.Enhancer;
import org.junit.Test;

/**
 * @author robin
 * @version 1.0
 */
public class CglibProxyTest {

    @Test
    public void test() {
        //1.给Enhancer设置被代理对象
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(UserServiceImpl.class);
        enhancer.setCallback(new ProxyHandler(new UserServiceImpl()));
        //2.通过Enhancer产生代理
        UserServiceImpl userServiceImplProxy = (UserServiceImpl) enhancer.create();
        userServiceImplProxy.save(new User(1L, "张三"));
    }

}
